package cn.newgrand.netcall.integration.sms;

import java.util.Collection;

import cn.newgrand.common.CommonUtil;
import cn.newgrand.common.StringUtil;

/**
 * @author SidneyRen E-mail:SidneyRen@hotmail.com
 * @version create time：2010-12-18 下午01:24:52
 * 类说明
 */
public class SMS {
	private Collection<SMSContact> receivers;
	private String content;
	private SMSContact sender;
	
	public Collection<SMSContact> getReceivers() {
		return receivers;
	}
	public void setReceivers(Collection<SMSContact> receivers) {
		this.receivers = receivers;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public SMSContact getSender() {
		return sender;
	}
	public void setSender(SMSContact sender) {
		this.sender = sender;
	}
	/**
	 * sms转换成XML格式
	 * 
	 * "<sms><phones><phone><phone><phones><content><content><sms>"
	 * @return
	 */
	public String toXML(){
		if(CommonUtil.isEmpty(receivers)){
			return null;
		}
		if(StringUtil.isEmpty(content)){
			return null;
		}
		StringBuffer sb = new StringBuffer();
		sb.append("<sms>").append("<sender>").append("<id>").append(sender.getJid()).append("</id>").append("</sender>");
		sb.append("<receivers>");
		for (SMSContact receiver : receivers) {
			sb.append("<receiver>").append("<name>").append(receiver.getName()).append("</name>");
			sb.append("<phone>").append(receiver.getPhone()).append("</phone>").append("</receiver>");
		}
		sb.append("</receivers>").append("<content>").append(content).append("</content>").append("</sms>");
		return sb.toString();
	}
}
